package mysql

import (
	"context"
	"go.uber.org/zap"
	"golang-sgg-daijia/internal/model"
)

type CustomerLoginLogDao interface {
	Create(ctx context.Context, customer *model.CustomerLoginLog) error
}

func NewCustomerLoginLogDao(
	r *MysqlClient,
) CustomerLoginLogDao {
	return &customerLoginLogDao{
		MysqlClient: r,
	}
}

type customerLoginLogDao struct {
	*MysqlClient
}

func (r *customerLoginLogDao) Create(ctx context.Context, customerLog *model.CustomerLoginLog) error {
	if err := r.DB(ctx).Create(customerLog).Error; err != nil {
		r.logger.WithContext(ctx).Error("customerLoginLogDao|Create(", zap.Any("data", map[string]interface{}{
			"customerLog": *customerLog,
		}), zap.Error(err))
		return err
	}
	return nil
}
